/**
 * 资源管理
 * 涉及到ui,prefab ，音效等资源可以在这里预加载 
 * 
 */


export enum uiPreName {
    addEngry = 'addEngry',      //增加体力 
    addGold = 'addGold',        //增加金币 元宝
    addTiShi = 'addTiShi',      //增加提示道具
    //GameOver = 'GameOver',          //游戏over
    timeOver = 'timeOver',           //时间耗尽
    selectkuang = 'selectkuang',    //找茬选答案 框 
    cha = 'cha',                    //叉号
    texiao = 'texiao',              //粒子特效
    pausepanel = 'pausepanel',      //暂停
    checkoutPanel = 'checkoutPanel', //关卡
    check_item0 = 'check_item0',
    check_item1 = 'check_item1',
    check_item2 = 'check_item2',
    check_item3 = 'check_item3',
}

export enum soundName {
    // game_bg0 = 'game_bg0',        //主音乐
    // game_bg1 = 'game_bg1',
    // game_bg2 = 'game_bg2',
    // game_bg3 = 'game_bg3',
    main_bg = 'main_bg',
    answerright = 'answerright',
    error = 'error',
    fail = 'fail',
    win = 'win',
    hit = 'hit',
    click = 'click',
}

export default class gamePrefabMgr {

    private static __instance: gamePrefabMgr;
    public static get Instance() {
        if (null == this.__instance) {
            this.__instance = new gamePrefabMgr();
        }
        return this.__instance;
    }

    jilv = 0
    allResNum = 0

    uiPre = []
    soundRes = []

    public Initial() {
        //this.isloadOver = !1
        this.jilv = 0
        var self = this

        //ui数量
        for (const key in uiPreName) {
            if (Object.prototype.hasOwnProperty.call(uiPreName, key)) {
                this.allResNum++
            }
        }
        //音效资源数
        for (const key in soundName) {
            if (Object.prototype.hasOwnProperty.call(soundName, key)) {
                this.allResNum++
            }
        }

        //加载ui
        for (const key in uiPreName) {
            if (Object.prototype.hasOwnProperty.call(uiPreName, key)) {
                let uiname = uiPreName[key]
                cc.resources.load('prefab/Ui/' + uiname, cc.Prefab, (err, assert) => {
                    if (err) return console.log('err=', err)
                    self.jilv++
                    gamePrefabMgr.Instance.uiPre[uiname] = assert as cc.Prefab
                })
            }
        }

        //加载音乐
        for (const key in soundName) {
            if (Object.prototype.hasOwnProperty.call(soundName, key)) {
                let uiname = soundName[key]
                cc.resources.load('Sound/' + uiname, (err, assert) => {
                    if (err) return console.log('err=', err)
                    self.jilv++
                    gamePrefabMgr.Instance.soundRes[uiname] = assert
                })
            }
        }
    }
}
